package com.wl.week_01;

import java.io.UnsupportedEncodingException;
import java.time.LocalDate;
import java.util.Scanner;

/**
 * 往年历
 * @author TaiZai
 * @data 2024/9/23 14:48
 */
public class Demo_1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        // 输出往年历
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入年份：");
        int year = sc.nextInt();
        System.out.println("请输入月份：");
        int month = sc.nextInt();

        // 获取年份对象
        LocalDate yearObj = LocalDate.of(year, month, 1);

        // 获取当月多少天
        int daysOfMonth = yearObj.lengthOfMonth();

        // 获取星期几
        int weekday = (int) yearObj.getDayOfWeek().getValue();

        // 输出表头
        System.out.println("日\t一\t二\t三\t四\t五\t六");

        // 输出空格
        for (int i = 0; i < weekday - 1; i++) {
            System.out.print("\t");
        }

        // 输出每一天
        for (int i = 1; i <= daysOfMonth; i++) {
            System.out.print(i + "\t");
            if ((i + weekday - 1) % 7 == 0) {
                System.out.println();
            }
        }
    }
}
